//
//  GDImageViewController.m
//  Gunterapple
//
//  Created by 热带雨林 on 2021/2/1.
//  Copyright © 2021 热带雨林. All rights reserved.
//

#import "GDImageViewController.h"
#import "armImageModel.h"

@interface GDImageViewController ()
@property (nonatomic, strong) UIButton *dissmissBtn;
@property (nonatomic, strong) UIImageView *imaView;
@property (nonatomic, strong) UILabel *dayLabel;
@property (nonatomic, strong) UILabel *dateLabel;
@property (nonatomic, strong) numDateChangeStrDate *changeDate;
@property (nonatomic, strong) colorChangeWithImageTool *colorTool;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation GDImageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置背景透明
//    self.view.backgroundColor = [[UIColor clearColor]colorWithAlphaComponent:0.7f];
    self.changeDate = [[numDateChangeStrDate alloc]init];
    self.colorTool = [[colorChangeWithImageTool alloc]init];
 //毛玻璃效果  只是设置为背景
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc]initWithEffect:effect];
    [self.view addSubview:effectView];
    UIEdgeInsets padding = UIEdgeInsetsMake(0, 0, 0, 0);
    [effectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(padding);
    }];
    //返回按钮
    self.dissmissBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:self.dissmissBtn];
    [self.dissmissBtn setTitle:@"<返回>" forState:UIControlStateNormal];
    [self.dissmissBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.dissmissBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.dissmissBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(SJHeight);
        make.left.equalTo(self.view).offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 50));
    }];
    //背景图片
    NSArray *imageArray = [NSArray gg_arrayModelWithPlistName:@"ArmSizeImage.plist" withClassName:@"armImageModel"];
    armImageModel *model = imageArray[arc4random() % 30] ;
    self.imaView = [[UIImageView alloc]initWithFrame:CGRectZero];
    self.imaView.layer.cornerRadius = 20.0f;
    self.imaView.layer.masksToBounds = YES;
    self.imaView.image = [UIImage imageNamed:model.name];
    self.imaView.contentMode = UIViewContentModeScaleAspectFill;
    self.imaView.clipsToBounds = YES;
    [self.view addSubview:self.imaView];
    [self.imaView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
        make.size.mas_equalTo(CGSizeMake(GDScreenW - 60, GDScreenW + 120));
    }];
    
    //时间显示
    self.dayLabel = [[UILabel alloc]init];
    [self.imaView addSubview:self.dayLabel];
    self.dayLabel.font = [UIFont fontWithName:Helvetica size:90];
    self.dayLabel.textColor = [UIColor whiteColor];
    [self.dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imaView).offset(30);
        make.left.equalTo(self.imaView).offset(20);
    }];
    
    self.dateLabel = [[UILabel alloc]init];
    [self.imaView addSubview:self.dateLabel];
    self.dateLabel.font = [UIFont systemFontOfSize:20];
    self.dateLabel.textColor = [UIColor whiteColor];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dayLabel.mas_bottom).offset(5);
        make.left.equalTo(self.dayLabel);
    }];
    
    //获得时间
    [self getDateStr];
    
    //显示文本信息
    self.titleLabel = [[UILabel alloc]init];
    [self.imaView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:22];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.text = @"虽是个梦，我已经不知如何是好了";
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.imaView.mas_bottom).offset(-70);
        make.left.equalTo(self.dateLabel);
        make.width.mas_lessThanOrEqualTo(200);
    }];
    //
    self.nameLabel = [[UILabel alloc]init];
    [self.imaView addSubview:self.nameLabel];
    self.nameLabel.font = [UIFont systemFontOfSize:13];
    self.nameLabel.text = @"《龙猫》";
    self.nameLabel.textColor = [UIColor whiteColor];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
        make.left.equalTo(self.titleLabel);
    }];
    
    //根据背景设置文字颜色
    [self.colorTool setTextColor:self.imaView whith:self.dayLabel];
    [self.colorTool setTextColor:self.imaView whith:self.dateLabel];
    [self.colorTool setTextColor:self.imaView whith:self.nameLabel];
    [self.colorTool setTextColor:self.imaView whith:self.titleLabel];
    
}

- (void)getDateStr{
    // 通过日期组件对象获取日期某一部分,不需要给日期加8小时就能获取本地时间.这让笔者感到困惑.
    //    获取当前时间(格林尼治时间)
        NSDate *localDate = [NSDate date];
        
    // 创建日期组件对象
        NSDateComponents *dateComponents = [[NSDateComponents alloc] init];

    // 创建日历对象
        NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
        
    // 给日期组件对象赋值
        NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
        dateComponents = [calendar components:unitFlags fromDate:localDate];
        NSLog(@"localDate = %@", localDate);
    
        NSLog(@"%ld", dateComponents.year);
        NSLog(@"%ld", dateComponents.month);
    NSString *month = [self.changeDate inputDateWithNumDate:dateComponents.month];
    self.dateLabel.text = [NSString stringWithFormat:@"%@.%ld",month,dateComponents.year];
        NSLog(@"%ld", dateComponents.day);
    self.dayLabel.text = [NSString stringWithFormat:@"%ld",dateComponents.day];
        NSLog(@"%ld", dateComponents.hour);
        NSLog(@"%ld", dateComponents.minute);
        NSLog(@"%ld", dateComponents.second);
}
- (void)click{
    [self dismissViewControllerAnimated:NO completion:nil];
}


@end
